/**
 * @author fenglei.you
 */
Me.Stage=function(width,height){
	this.width=width;
	this.height=height;
	
	this.context=null;
	
	/************************/
	this.childs=[];
	
	/************************/
	this.clickListener=[];
	this.touchStartListener=[];
	this.touchEndListener=[];
	this.touchMoveListener=[];
	
	Me.globalStage = this;
}

/**********************canvas********************/
Me.Stage.prototype._init=function(x,y){
	var canvas = document.createElement('canvas');
	canvas.width=this.width;
	canvas.height=this.height;
	if(x&&y){
		canvas.style.position='absolute';
		canvas.style.left=x;
		canvas.style.top=y;
	}else{
		canvas.style.position='relative';
		canvas.style.margin='0 auto';
	}
	document.body.appendChild(canvas);
	
	this.context = canvas.getContext('2d');
}
Me.Stage.prototype.init=function(x,y,custome){
	this._init(x,y);
	if(custome){
		custome();
	}
}
Me.Stage.prototype.getContext=function(){
	return this.context;
}
/*********************child**********************/
Me.Stage.prototype.appendChild=function(child,index){	
	child.zindex = index || (this.childs.length+1);
	this.childs.push(child);	
}

/**********************click*********************/
Me.Stage.prototype._onclick=function(event){
	Trace.log("stage on click");
}
Me.Stage.prototype.onclick=function(event){
	Me.Collections.eachCall(this.clickListener);
	this._onclick(event);
}
Me.Stage.prototype.addClickListener=function(listener,index){
	if(index){
		this.clickListener[index]=listener;
	}else{
		this.clickListener.push(listener);
	}	
}


